﻿using Gym.Domain.Common.Entities;
using Gym.Domain.Common.ValueObjects;
using Gym.Domain.RoomAggregate;
using Gym.Infrastructure.Persistence.Converters;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gym.Infrastructure.Persistence.Configurations
{
    public class RoomConfigurations : IEntityTypeConfiguration<Room>
    {
        public void Configure(EntityTypeBuilder<Room> builder)
        {
            builder.HasKey(r => r.Id);

            builder.Property(r => r.Id)
                .ValueGeneratedNever();

            builder.Property("_maxDailySessions")
                .HasColumnName("MaxDailySessions");

            builder.Property<Dictionary<DateOnly, List<Guid>>>("_sessionIdsByDate")
                .HasColumnName("SessionIdsByDate")
                .HasValueJsonConverter();

            builder.OwnsOne<Schedule>("_schedule", sb =>
            {
                sb.Property<Dictionary<DateOnly, List<TimeRange>>>("_calendar")
                    .HasColumnName("ScheduleCalendar")
                    .HasValueJsonConverter();

                sb.Property(s => s.Id)
                    .HasColumnName("ScheduleId");
            });

            builder.Property(r => r.Name);
            builder.Property(r => r.GymId);
        }
    }
}
